jQuery.validator.addMethod("notEqual", function(value, element, param) {
		  return this.optional(element) || value != param;
		}, "Please specify a different (non-default) value");
$(document).ready(function() {
	
	$('input[name=company]').change(function() {
			var input = $('#company').val();
			$('#companyId').val(input);
	});

	$('input[name=empNum]').change(function() {
		var input = $('#empNum').val();
		$('#empNumId').val(input);
	});	
	
	$('select[name=country]').change(function() {
		var input = $('#country').val();
		if(input!=""){
		$('#countryId').val(input);
		}
	});	
	
	
	$('input[name=password]').change(function() {
		var input = $('#password').val();
		$('#passwordId').val(input);
	});	
	
	var validator = $("#ownerRegister").validate({
		rules: {
			fName: "required",
			lName: "required",
			nickName:"required",
//			phone:{
//				required: true,
//				number:true
//			},
			empNum:{
				required: true,
				number:true
			},
			country: {
				required: false,
				notEqual: "0"
			},
			password: {
				required: true,
				minlength: 5,
				maxlength:10
			},
			repassword: {
				required: true,
				minlength: 5,
				maxlength: 10,
				equalTo: "#password"
			},
			email: {
				required: true,
				email: true
				,remote: "validator/checkemail"
			},
			company: {
				required: true,
				remote: "validator/checkcompany"
			}
			,checkbox: { 
		        required: true
	        }
		},
		messages: {
			fName: {required : $("input#fNameRequired").val()},
			lName:  {required  : $("input#lNameRequired").val()},
			nickName:  {required  : $("input#userNameRequired").val()},
//			phone:  {
//				required: "Provide a Phone",
//				number: jQuery.format("Enter numbers only")
//			},
			empNum:  {
				required: $("input#empNumRequired").val(),
				number: jQuery.format($("input#empNumNumber").val())
				},
			country: {
					notEqual: $("input#countryNotEqual").val()
			},
			password:  {
				required:  $("input#passwordRequired").val(),
				minlength: jQuery.format($("input#passwordMinlength").val()),
				maxlength: jQuery.format($("input#passwordMaxlength").val())
			},
			repassword: {
				required: $("input#repasswordRequired").val(),
				equalTo: $("input#repasswordEqualTo").val()
			},
			email: {
				required: $("input#emailRequired").val(),
				email: $("input#emailEmail").val()
			   ,remote: jQuery.format($("input#emailRemote").val())
			},
			company: {
				required: $("input#companyRequired").val(),
			    remote: jQuery.format($("input#companyRemote").val())
			}
			,checkbox:{
				required: $("input#checkboxRequired").val()
			}
		},
		submitHandler: function() {
			 form.submit();
		},
		success: function(label) {
		}
	});
	cancelButtonHandler();
});

/**
 * Cancel button handler
 */
function cancelButtonHandler(){
	$("#cancelButton").click(function() {
		document.location.href='register';
	});	
}

